package edu.gatech.cs2340.teamrocket.view.main;

import java.awt.*;
import javax.swing.*;
import edu.gatech.cs2340.teamrocket.model.team.Team;

/**
 * This is the right panel of the main game panel
 * @author Wai Chip Ngai
 *
 */
@SuppressWarnings("serial")
public class RightPanel extends JPanel{
    private final ButtonGroup paceGroup = new ButtonGroup();
    private final ButtonGroup rationsGroup = new ButtonGroup();
    private JRadioButton hungry, enough, fat, slowPoke, walking, running, biking, thunderbolt; // why is this not an array? who knows...

    public RightPanel(){
        setPreferredSize(new Dimension(160, 568));
        setLayout(new GridLayout(14,1));
        setBorder(BorderFactory.createTitledBorder(
                BorderFactory.createEtchedBorder(), "This Turn: "));

        JLabel lblRations = new JLabel("  Rations");
        add(lblRations);
        hungry = new JRadioButton("Minimum");
        hungry.setSelected(true);
        rationsGroup.add(hungry);
        add(hungry);

        enough = new JRadioButton("Moderate");
        rationsGroup.add(enough);
        add(enough);

        fat = new JRadioButton("Maximum");
        rationsGroup.add(fat);
        add(fat);

        JLabel lblPace = new JLabel("  Pace");
        add(lblPace);

        slowPoke = new JRadioButton("Slowpoke");
        slowPoke.setSelected(true);
        paceGroup.add(slowPoke);
        add(slowPoke);

        walking = new JRadioButton("Walking");
        paceGroup.add(walking);
        add(walking);

        running = new JRadioButton("Running");
        paceGroup.add(running);
        add(running);

        biking = new JRadioButton("Biking");
        paceGroup.add(biking);
        add(biking);

        thunderbolt = new JRadioButton("Thunderbolt");
        paceGroup.add(thunderbolt);
        add(thunderbolt);

    }

    /**
     * Go through the radio buttons to see the selected initial speed
     * @return an int representing selected initial speed
     */
    public int getSelectedSpeed(){

        if(slowPoke.isSelected()){
            return Team.MIN_SPEED;
        }else if(walking.isSelected()){
            return Team.SLOW_SPEED;
        }else if(running.isSelected()){
            return Team.MID_SPEED;
        }else if(biking.isSelected()){
            return Team.FAST_SPEED;
        }else{
            return Team.MAX_SPEED;
        }
    }

    public void setSelectedSpeed(int i){
        switch(i){
            case 1:
                slowPoke.setSelected(true);
                break;
            case 2:
                walking.setSelected(true);
                break;
            case 3:
                running.setSelected(true);
                break;
            case 4:
                biking.setSelected(true);
                break;
            case 5:
                thunderbolt.setSelected(true);
                break;
        }
    }

    /**
     * Go through the radio buttons to see the selected rations
     * @return an int representing the selected rations
     */
    public int getSelectedRations(){

        if (hungry.isSelected()){
            return Team.MIN_RATIONS;
        }else if(enough.isSelected()){
            return Team.MID_RATIONS;
        }else{
            return Team.MAX_RATIONS;
        }
    }
}
